<script id="guidanceInfo" type="text/html">
<thead>
	<tr style="width: 100%;">
		<td>名称</td>
		<td>规格型号</td>
		<td>单位</td>
		<!--<td>税率%</td>-->
		<td>除税价</td>
		<td class="hsj">含税价</td>
		{{#  if(d[0].maxPrice){ }}<td>最高价</td>{{#  } }}
		{{#  if(d[0].minPrice){ }}<td>最低价</td>{{#  } }}
		<td>历史价</td>
		<td>备注</td>
	</tr>
</thead>
<tbody>
	{{# for(var i = 0, len = d.length; i < len; i++){ }}
		<tr> 
			<td><span class="ccyc">{{#  if(d[i].materialName){ }}{{d[i].materialName}}{{#  } }}</span></td>
			<td><span class="ccyc">{{#  if(d[i].specificcations){ }}{{d[i].specificcations}}{{#  } }}</span></td>
			<td>{{#  if(d[i].units){ }}{{d[i].units}}{{#  } }}</td>
			<td>{{#  if(d[i].noTaxPrice){ }}{{d[i].noTaxPrice}}{{#  } }}</td>
			<td>{{#  if(d[i].taxPrice){ }}{{d[i].taxPrice}}{{#  } }}</td>  
			<td><img class="pictureI" src="/ceca_two/img/echars.png" style="cursor: pointer;"></td>
			{{#  if(d[i].maxPrice){ }}<td>{{d[i].maxPrice}}</td>{{#  } }}
			{{#  if(d[i].minPrice){ }}<td>{{d[i].minPrice}}</td>{{#  } }}
			<td class="picture">
				<span style="display: block;text-overflow: ellipsis;max-width: 250px;overflow: hidden;white-space: nowrap;" title='{{d[i].remarks}}'>{{#  if(d[i].remarks){ }}{{d[i].remarks}}{{#  } }}</span>
			</td>
			<!--{{#  if(d[0].remakes){ }}<td>{{d[i].remakes}}</td>{{#  } }}-->
		</tr>
	{{# } }}
</tbody>
</script>
<div class="type" style="z-index: 999;">
	<div class="typeContent">
		<span class="top">高级选项：</span>
		<div class="city">
			<div class="cityclick" style="height: 58px;">
				<span class="cityS"></span>
				<i class="position"></i>
				<i class="arrow"><img src="/ceca_two/img/xxjdown_arrow.png" /></i>
			</div>
			<div class="typeMain"  style="height: auto;padding-bottom: 30px;">
				<div class="cityTypeMain">
					<span class="cityTip">请选择您需要的城市</span>
					<span class="chose">
						<i id="areaList">您选择了：</i>
					</span>
					<ul class="AllCity">
						<li class="cityOne"></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="major">
			<div class="majorclick" style="height: 58px;">
				<span class="majorS"></span>
				<i class="majorI">专业</i>
				<i class="arrow"><img src="/ceca_two/img/xxjdown_arrow.png"></i>
			</div>
			<div class="typeMain">
				<div class="majorTypeMain">
					<span class="majorTip">请选择您需要的专业</span>
					<span class="chose">
						<i id="majorList">您选择了：</i>
					</span>
					<ul class="Allmajor">
						<li class="majorOne">
						</li>
					</ul>
				</div>
			</div>
		</div>
		<div class="periods">
			<div class="perclick" style="height: 58px;">
				<span class="periodsS"></span>
				<i class="periodsI" style="width: 198px;overflow: hidden;height: 58px;">期次</i>
				<i class="arrow"><img src="/ceca_two/img/xxjdown_arrow.png"></i>
			</div>
			<div class="typeMain" style="height: auto;padding-bottom: 30px;min-height: 250px;">
				<div class="periodsTypeMain">
					<span class="periodsTip">请选择您需要的期数</span>
					<span class="chose">
						<i id="gunidanceList">您选择了：</i>
					</span>
					<ul class="Allperiods">
						<li class="periodsOne">
							<div class="abc"></div>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="weizao" style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;z-index: 998;display: none;">
	<ul class="top" style="position: absolute;top: 0;left: 0;width: 100%;height: 500px;"></ul>
	<ul class="bottom" style="position: absolute;bottom: 0;left: 0;width: 100%;height: 1140px;"></ul>
</div>

<script>
layui.use(['Router','filter','Zarea','Zutil','laytpl','laypage'], function(Router,filter,Zarea,Zutil){
	var laypage =layui.laypage;
	var laytpl = layui.laytpl;
	var Router = layui.Router;
	var filter = layui.filter;
	var Zarea = layui.Zarea;
	var Zutil = layui.Zutil;
	var Url=Router.link.materialPrice.getGuidance;
	var obj = {
		areaName:Zutil.decodeURI(window.atob(Zutil.getQueryString("areaName")  || "")),
		catalogId:Zutil.getQueryString("catalogId"),
		categoryCode:Zutil.getQueryString("categoryCode"),
		guidanceId:Zutil.getQueryString("guidanceId"),
		areaCode:Zutil.getQueryString("areaCode"),
		major:Zutil.decodeURI(window.atob(Zutil.getQueryString("major")  || "")),
		pageNumber:Zutil.getQueryString("pageNumber") || 1,
	    pageSize:Zutil.getQueryString("pageSize") || 10,
	    sou:Zutil.decodeURI(window.atob(Zutil.getQueryString("sou")  || "")),
	    treeId : Zutil.getQueryString("treeId") || "" ,
	    aYear : Zutil.getQueryString("aYear") || ""
    };
    if(obj.sou && obj.sou != "")$(".sou").val(obj.sou);
    if(!Zutil.getQueryString("areaCode")){
    	var nowCity =sessionStorage.getItem("nowCity");
    	if(nowCity == null | nowCity == "null"){
			$.getJSON("http://restapi.amap.com/v3/ip?key=6a0ef5788c9d08d8e06effc034904740", function(result){
				if(result && result.status) {
					sessionStorage.setItem("nowCity",JSON.stringify(result));
					obj.areaName = nowCity.city;
					obj.areaCode = nowCity.adcode;
					$(".position").html(obj.areaName);
					getGuidanceByCode();
				}
			});
		}else{
			nowCity =  jQuery.parseJSON(nowCity);
			obj.areaName=nowCity.city;
			obj.areaCode=nowCity.adcode;
			$(".position").html(obj.areaName);
			getGuidanceByCode();
		}
    }else{
    	if(obj.areaName && obj.areaName != "")$(".position").html(obj.areaName);
    	getGuidanceByCode();
    }
    
    function makeUrl(){
    	var baseHref="/ceca_two/modules/guidance/governmentInformation.html?";
    	
    	if(obj.guidanceId)baseHref+="&guidanceId="+obj.guidanceId;
    	if(obj.areaCode)baseHref+="&areaCode="+obj.areaCode;
    	if(obj.major)baseHref+="&major="+window.btoa(Zutil.encodeURI(obj.major|| "" ));
    	if(obj.pageNumber)baseHref+="&pageNumber="+obj.pageNumber;
    	if(obj.pageSize)baseHref+="&pageSize="+obj.pageSize;
    	if(obj.sou)baseHref+="&sou="+window.btoa(Zutil.encodeURI(obj.sou|| "" ));
    	if(obj.areaName)baseHref+="&areaName="+window.btoa(Zutil.encodeURI(obj.areaName|| "" ));
    	if(obj.catalogId)baseHref+="&catalogId="+obj.catalogId;
    	if(obj.categoryCode)baseHref+="&categoryCode="+obj.categoryCode;
    	if(obj.treeId)baseHref+="&treeId="+obj.treeId;
    	if(obj.aYear)baseHref+="&aYear="+obj.aYear;
    	window.location.href = baseHref;
    }
	$(".cityclick").on("click",function(){
		$(".sou").val("");
		delete obj.sou;
		$("#gunidanceList i").remove();
		if($(this).next(".typeMain").css("display") == "none") {
			$(".typeMain").hide();
			$(".cityTypeMain").hide();
			$(".majorTypeMain").hide();
			$(this).next(".typeMain").show();
			$(".cityTypeMain").show();
			$(".weizao").show();
		}else{
			$(this).next(".typeMain").hide();
			$(".cityTypeMain").hide();
			$(".weizao").hide();
		}
		$("#areaList i").remove();
		$(".cityOne i").remove();
		$.post("/guidance_service/front/guidance/getArea.do",{},function(rlt){
			for(var i in rlt.data){
				$(".cityOne").append("<i data-areacode="+rlt.data[i].areaCode+"  title='"+rlt.data[i].province+"'>"+rlt.data[i].province+"</i>")
			}
			$(".cityOne i").unbind("click").on("click",function (){ // 省
				var thisProvince = $(this).html();
				$(".position").html(thisProvince)
				$("#areaList").append("<i style='color: red;'>"+thisProvince+"</i>")
				$.post("/guidance_service/front/guidance/getArea.do",{"province":thisProvince},function(rlt){
					$(".cityOne").empty();
					for(var i in rlt.data){
						if(rlt.data[i].city){
							if(rlt.data[i].county){
								$(".cityOne").append("<i  title='"+rlt.data[i].city+"'>"+rlt.data[i].city+"</i>");
							}else{
								$(".cityOne").append("<i data-areacode="+rlt.data[i].areaCode+" title='"+rlt.data[i].city+"'>"+rlt.data[i].city+"</i>");
							}
						}else{
							$(".cityOne").append("<i data-areacode="+rlt.data[i].areaCode+"  title='"+rlt.data[i].province+"'>"+rlt.data[i].province+"</i>")
						}
					}
					$(".cityOne i").unbind("click").on("click",function (){ //市
						var thisCity = $(this).html();
						var thisCode = $(this).attr("data-areaCode") ;
						$(".position").html(thisCity)
						if(thisCode){
							$(".cityclick .position").html(thisCity);
							$(".city .typeMain").hide();
							$(".cityTypeMain").hide();
							$(".weizao").hide();
							
							delete obj.treeId;
							delete obj.catalogId;
							delete obj.guidanceId;
							delete obj.categoryCode;
							delete obj.major;
							delete obj.pageNumber;
							delete obj.pageSize;
							delete obj.sou;
							obj.areaName=thisCity;
							obj.areaCode=thisCode;
							makeUrl();
						}else{
							$("#areaList").append("<i style='margin: 0 3px;color:red'>></i><i style='color: red;'>"+thisCity+"</i>");
							$.post("/guidance_service/front/guidance/getArea.do",{"province":thisProvince,"city":thisCity},function(rlt){
								$(".cityOne").empty();
								for(var i in rlt.data){
									if(rlt.data[i].county){
										$(".cityOne").append("<i  data-areacode="+rlt.data[i].areaCode+" title='"+rlt.data[i].county+"'>"+rlt.data[i].county+"</i>")
									}else{
//										$(".cityOne").append("<i data-areacode="+rlt.data[i].areaCode+"  title='"+rlt.data[i].city+"'>"+rlt.data[i].city+"</i>")
									}
								}
								$(".cityOne i").unbind("click").on("click",function (){ //区
									var areaName =$(this).html();
									var thisCode = $(this).attr("data-areaCode");
									$(".position").html(areaName)
									$(".periodsI").html("期次");
									$(".city .typeMain").hide();
									$(".weizao").hide();
									$(".cityTypeMain").hide();
									$(".cityclick .position").html(areaName);
									delete obj.treeId;
									delete obj.catalogId;
									delete obj.guidanceId;
									delete obj.categoryCode;
									delete obj.major;
									delete obj.pageNumber;
									delete obj.pageSize;
									delete obj.sou;
									obj.areaName=areaName;
									obj.areaCode=thisCode;
									makeUrl();
									return false;	
								});
							});
						}
						return false;
					});
				});
				return false;
			});
		});
	return false;	
})	
$(".majorclick").on("click",function (){
	$(".sou").val("");
	delete obj.sou;
	if ($(this).next(".typeMain").css("display") == "none") {
		$(".typeMain").hide();
		$(".cityTypeMain").hide();
		$(".majorTypeMain").hide();
		$(".periodsTypeMain").hide();
		$(this).next(".typeMain").show();
		$(".majorTypeMain").show();
		$(".weizao").show();
	}else{
		$(this).next(".typeMain").hide();
		$(".majorTypeMain").hide();
		$(".weizao").hide();
	}
})

$(".perclick").on("click",function (){
	$(".sou").val("");
	delete  obj.sou;
	if ($(this).next(".typeMain").css("display") == "none") {
		$(".typeMain").hide();
		$(".cityTypeMain").hide();
		$(".majorTypeMain").hide();
		$(".periodsTypeMain").hide();
		$(this).next(".typeMain").show();
		$(".periodsTypeMain").show();
		$(".weizao").show();
		if (obj.aYear) {
			$("#gunidanceList").append("<i style='color: red;'>"+obj.aYear+"</i>")
			
			for (i = 0 ; i < $(".periodsOne i").length ; i++ ) {
				
				if ($(".periodsOne i").eq(i).html() == obj.aYear) {
					$(".periodsOne i").eq(i).click()
				}
				
			}
			
			
		}
		
	}else{
		$(this).next(".typeMain").hide();
		$(".periodsTypeMain").hide();
		$(".weizao").hide();
	}
})
function getGuidanceByCode(){
	
	delete obj.guidanceId;
	$.post("/guidance_service/front/guidance/getGuidanceName.do",obj,function (data){
			var data = data.data;
			obj.guidanceId=Zutil.getQueryString("guidanceId")?Zutil.getQueryString("guidanceId"):data.newest.guidanceId;
			
			loadRight();
			$(".majorOne").html("");
			for(var i in data.major){
				$(".majorOne").append("<i>"+data.major[i]+"</i> ");
			}
			$(".majorOne i").on("click",function (){
				var thisMajor = $(this).html();
				$(".majorI").html(thisMajor);
				obj.major = thisMajor;
				delete obj.treeId;
				delete obj.catalogId;
				delete obj.guidanceId;
				delete obj.categoryCode;
				delete obj.pageNumber;
				delete obj.pageSize;
				delete obj.sou;
			    makeUrl();
				$(".typeMain").hide();
				$(".weizao").hide();
				$(".majorTypeMain").hide();
				return false;
			})
			$(".periodsI").html("期次")
			$(".periodsOne").empty();
			var yeararr = [] ;
			$(".periodsOne").append("<div style='margin: 5px 0;'></div>")
			if (data.guidance) {
				for (i = 0 ; i < data.guidance.length ; i++) {
					if (yeararr.indexOf(data.guidance[i].year) == -1) {
						yeararr.push(data.guidance[i].year);
						$(".periodsOne div").append("<i>"+data.guidance[i].year+"</i>");
					}
				}
			}
			
			$(".periodsOne i").on("click",function (){
				$(".periodsOne span").remove();
				var thisYear = $(this).html();
				$("#gunidanceList i").remove();
				$("#gunidanceList").append("<i style='color: red;'>"+thisYear+"</i>");
				obj.aYear = thisYear ;
				for (i = 0 ; i < data.guidance.length ; i++) {
					if (data.guidance[i].year == thisYear) {
						if (Zutil.getQueryString("guidanceId") == data.guidance[i].guidanceId) {
							$(".periodsOne").append("<span data-guidanceId = "+data.guidance[i].guidanceId+" style='color:red'>"+data.guidance[i].guidanceName+"</span>")
						}else{
							$(".periodsOne").append("<span data-guidanceId = "+data.guidance[i].guidanceId+">"+data.guidance[i].guidanceName+"</span>")
						}
					}
				}
				$(".periodsOne span").on("click",function (){
					$(".perclick .periodsI").html($(this).html());
					$("#guidanceName").html($(this).html())
					obj.guidanceId = $(this).attr("data-guidanceId");
					delete obj.treeId;
					delete obj.catalogId;
					delete obj.categoryCode;
					delete obj.pageNumber;
					delete obj.pageSize;
					delete obj.sou;
				    makeUrl();
					$(".typeMain").hide();
					$(".periodsTypeMain").hide();
					$(".weizao").hide();
					return false;
				})
				$("#gunidanceList i").on("click",function (){
					$(".periodsOne span").remove();
					$("#gunidanceList i").remove();
					$(".periodsOne div").show();
					return false;
				});
				return false;
			});
		if (!data.major  || data.major[0] == "") {
			$(".majorOne").empty().html(data.major|| obj.major)
		}
//		if (Zutil.getQueryString("guidanceId")) {
//			
//		}
		
	});
}


$(".weizao").on("click",function (){
	$(this).hide();
	$(".typeMain").hide();
	$(".cityTypeMain").hide();
	$(".majorTypeMain").hide();
	$(".periodsTypeMain").hide();
})


function getList(obj){
	$.post("/guidance_service/front/guidance/infocopy/searchGuidanceInfoWithCate.do",obj,function(result){
		var  data = result.data;
		if (data.list.length > 0) {
			$(".yqts").show();
			$("#laypage").show();
			$("#totalRow").html(data.totalRow);
			laytpl(guidanceInfo.innerHTML).render(data.list, function(html){guidanceInfoText.innerHTML=html;});
			laypage({
			    cont: 'laypage'
			    ,pages: data.totalPage
			    ,curr:data.pageNumber
			    ,groups:data.pageSize
			    ,skin: '#ff0000'
			    ,jump: function(opt, first){
				    var curr = opt.curr;   //得到了当前页，用于向服务端请求对应数据
				    obj.pageNumber = curr|| 1;
				    if(!first){
				    	makeUrl();
				    }
				  }
			});
			for (i = 0 ; i < $("#guidanceInfoText tr").length ; i++) {
				var html = $("#guidanceInfoText tr").eq(i).find(".ccyc").find("font").html() || $("#guidanceInfoText tr").eq(i).find(".ccyc").html();
				$("#guidanceInfoText tr").eq(i).find(".ccyc").attr("title",html)
			}
			$(".remarks").on("click",function(){
				var tit = $(this).parents("tr").find(".ccyc").eq(0).html();
				var remarks = $(this).next(".remakehide").html();
				$("#remakebox .title").empty().html(tit);
				$("#remakebox .con p").empty().html(remarks);
				$("#remakebox").toggle();
			})
			$("#remakebox .close").on("click",function (){
				$("#remakebox").hide();
			})
		} else{
			$("#guidanceInfoText").empty();
			$(".yqts").hide();
			$("#laypage").hide();
			$("#guidanceInfoText").append("<tr><td rowspan='10' colspan='8'><div class='myss'>暂无搜索信息</div></td></tr>")
			$("#totalRow").html("0");
		}
		loadLeft(result.ext);
	});
}
$(".sou").on("keydown",function (event){
	e = event ? event :(window.event ? window.event : null);
	if (e.keyCode==13) {
		obj.sou = $(".search input").val().trim();
		delete obj.catalogId;
		delete obj.categoryCode;
		delete obj.pageNumber;
		delete obj.pageSize;
		delete obj.treeId; 
		makeUrl();
	}
})
$(".searchButton").click(function(){
	obj.sou = $(".search input").val().trim();
	delete obj.catalogId;
	delete obj.categoryCode;
	delete obj.pageNumber;
	delete obj.pageSize;
	delete obj.treeId; 
	makeUrl();
});

function loadLeft(obj){
//	$.post('/guidance_service/front/guidance/catalog/getCatalog.do',{"guidanceId":id},function(result){
		if(obj.data.length > 0){	
			for (i = 0 ; i < obj.data.length ; i++) {
				obj.data[i].id == 1 ? obj.data.splice(i,1) : "";
			}
			var t = $("#treeDemo");
			if(obj.type == "category"){
				t = $.fn.zTree.init(t,categorySetting, obj.data);
			}else{
				t = $.fn.zTree.init(t,catalogSetting, obj.data);
			}
			var thisTreeId = Zutil.getQueryString("treeId") || "" ;
			if (thisTreeId && thisTreeId !="") {
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				var node = treeObj.getNodeByParam("id",thisTreeId); 
                treeObj.selectNode(node,true);//指定选中ID的节点  
                treeObj.expandNode(node, true, false);//指定选中ID节点展开 
			}
			
		}
//	});
}

function loadRight(){
	$.post("/guidance_service/front/guidance/getGuidanceName.do",obj,function (rlt){
		if(rlt.data.newest){
			$(".majorI").html(rlt.data.newest.major || "专业");
			$("#guidanceName").html(rlt.data.newest.guidanceName || "暂无信息价名称");
			$("#explains").html(rlt.data.newest.explains || "本期次暂无详细说明");
			$(this).find(".buttonZ").html("展开");
			$("#explains").height("70");
		}
	});
	getList(obj);
}

var catalogSetting = {
	view:{
		dblClickExpand: false,
		showLine: false,
		expandSpeed: "",
		addDiyDom:addDiyDom
	},
	data: {
		simpleData: {
			enable: true,
			idKey: "catalogId",
			pIdKey: "catalogParentId"
		},
		key:{
	        name: "catalogName"
       }
	},
   callback: {
		onClick: messageFilter
   }
};
var categorySetting = {
	view:{
		dblClickExpand: false,
		showLine: false,
		expandSpeed: "",
		addDiyDom:addDiyDom
	},
	data: {
		simpleData: {
			enable: true,
			idKey: "categoryId",
			pIdKey: "categoryParentId"
		},
		key:{
	        name: "categoryName"
       }
	},
   callback: {
		onClick: messageFilter
   }
};
	
	
function messageFilter(e,treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo");
	zTree.expandNode(treeNode);
	if(treeNode.level == 0){
		obj.categoryCode ="";
		if(treeNode.children){
			$.each(treeNode.children, function(index,val) {
				if(val.categoryCode){
					obj.categoryCode += index < treeNode.children.length-1? val.categoryCode+";":val.categoryCode;
				}
			});
		}
	}else{
		obj.categoryCode = treeNode.categoryCode;
	}
	obj.pageNumber=1;
	obj.pageSize=10;
	obj.catalogId = treeNode.catalogId;
	obj.treeId = treeNode.id
	makeUrl(obj);
}
function addDiyDom(treeId, treeNode) {
	var spaceWidth = 5;
	var switchObj = $("#" + treeNode.tId + "_switch"),
	icoObj = $("#" + treeNode.tId + "_ico");
	switchObj.remove();
	icoObj.before(switchObj);
	if (treeNode.level > 1) {
		var spaceStr = "<span style='display: inline-block;width:" + (spaceWidth * treeNode.level)+ "px'></span>";
		switchObj.before(spaceStr);
	}
}
$(".navTitle").on("click",function (){
	delete obj.catalogId;
	delete obj.categoryCode;
	delete obj.treeId;
	makeUrl();
//	getList(obj);
  $.fn.zTree.getZTreeObj("treeDemo").expandAll(false);
})
	
});
</script>
<script type="text/javascript">
	var objTop = $(".type").offset().top
    $("html,body").animate({scrollTop:objTop},200)
</script>